package com.sias.reflection.question;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * @author 吴文杰
 * @version 1.0
 * @createTime 2023-05-02 11:36:40
 */
@SuppressWarnings("all")
public class ReflectionQuestion{
  public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
    // Cat cat = new Cat();
    // cat.hi();

    Properties properties = new Properties();
    properties.load(new FileInputStream("reflection/src/main/resources/re.properties"));
    String classfullpath = properties.get("classfullpath").toString();
    String methodName = properties.get("method").toString();
    // System.out.println("classfullpath:"+classfullpath);
    // System.out.println("method:"+methodName);

    Class<?> cls = Class.forName(classfullpath);
    // Cat cat = (Cat)cls.newInstance();
    Object cat = cls.newInstance();
    System.out.println(cat.getClass());
    Method clsMethod = cls.getMethod(methodName);
    clsMethod.invoke(cat);
  }
}
